package org.clipjoint.service.impl;

import org.clipjoint.dao.AdminDao;
import org.clipjoint.dao.impl.AdminDaoImpl;
import org.clipjoint.entity.Admin;
import org.clipjoint.service.AdminService;

import java.sql.SQLException;
import java.util.Date;


/**
 * @author 陈光耀
 * @date 2021/2/22
 */
public class AdminServiceImpl implements AdminService {

    private AdminDao adminDao = new AdminDaoImpl();


    //登录
    @Override
    public Admin getByUsername(Admin admin) throws SQLException {

        Admin result = adminDao.selectOne(admin);

        //记录最后的登录时间
        if (result != null) {

            result.setLast_login_time(new Date());

            int updateResult = adminDao.updatellt(result);
        }

        return adminDao.selectOne(admin);
    }


    //修改密码
    @Override
    public int updatePassword(Long id, String password) throws SQLException {
        Admin admin = adminDao.selectOne(Admin.builder().id(id).build());
        admin.setPassword(password);
        int result = adminDao.updatePassword(admin);
        return result;
    }


    //修改个人信息
    @Override
    public int updateInfo(Admin admin) throws SQLException {

        int updateInfoResult = adminDao.updateInfo(admin);

        return updateInfoResult;
    }

}
